//
//  BettingViewController.m
//  WangLottery
//
//  Created by 黄修勇 on 12-4-23.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BettingViewController.h"
#import "BettingCell.h"
#import "DoubleColorBettingViewController.h"
#import "ThreeDBettingViewController.h"
#import "ArraneFiveViewController.h"
#import "QiLeCaiViewController.h"

@interface BettingViewController ()

@end

@implementation BettingViewController

-(void)dealloc{

    [bettyTableView release];
    [titleArray release];
    [imageNameArray release];
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)loadView{

    [super loadView];
    bettyTableView=[[UITableView alloc]initWithFrame:CGRectMake(0.0f,0.0f, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    bettyTableView.backgroundColor=[UIColor whiteColor];
    bettyTableView.dataSource=self;
    bettyTableView.delegate=self;
    bettyTableView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    
   // bettyTableView.backgroundView.alpha=0.5;
    [self.view addSubview:bettyTableView];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    
    titleArray=[[NSArray alloc]initWithObjects:@"专业选号",@"双色球",@"大乐透",@"3D",@"排列三",@"排列五",@"七乐彩",@"七星彩",@"22选5", nil];
    
    imageNameArray=[[NSArray alloc]initWithObjects:@"",@"shuangseqiu.png",@"",@"3d.png",@"", nil];
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];
    
    UIButton *refresh = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [refresh setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    refresh.frame=CGRectMake(0, 0, 40, 40);
    [refresh addTarget:self action:@selector(refreshView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:refresh];
    self.navigationItem.leftBarButtonItem = btn;
    [btn release];
    
    NSIndexPath *indexPath=[bettyTableView indexPathForSelectedRow];
    if (indexPath) {
        [bettyTableView deselectRowAtIndexPath:indexPath animated:YES];
    }
}

#pragma mark -UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 9;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 60.0f;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellString=@"betty";
    BettingCell *cell=[tableView dequeueReusableCellWithIdentifier:cellString];
    if (!cell) {
        cell=[[[BettingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString] autorelease];
        cell.backgroundColor=[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.4f];
    }
    
    cell.lotteryTypeImageView.image=[UIImage imageNamed:@"7happy.png"];
    cell.titleLable.text=[titleArray objectAtIndex:indexPath.row];
    if (indexPath.row!=0) {
        cell.isTodayLottery=YES;
        cell.mostMoneyText=@"1500万";
        cell.periodLabel.text=@"第2012001";
        cell.upDateLabel.text=@"截至日期 12月06日 19:00";
        cell.isShowMoneyLabel=YES;
    }else {
        cell.isTodayLottery=NO;
        cell.mostMoneyText=@"";
        cell.periodLabel.text=@"";
        cell.upDateLabel.text=@"";
        cell.isShowMoneyLabel=NO;
    }
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row==1) {
        DoubleColorBettingViewController *doubleColor=[[DoubleColorBettingViewController alloc]initWithNibName:@"DoubleColorBettingViewController" bundle:nil];
         doubleColor.title=@"双色球";
        [self.navigationController pushViewController:doubleColor animated:YES];
        
        doubleColor.lotteryType=LotteryTypeShuangSeQiu;
       
        [doubleColor release];

    }else if(indexPath.row==2){
    
        DoubleColorBettingViewController *doubleColor=[[DoubleColorBettingViewController alloc]initWithNibName:@"DoubleColorBettingViewController" bundle:nil];
        doubleColor.title=@"大乐透";
        [self.navigationController pushViewController:doubleColor animated:YES];
        
        doubleColor.lotteryType=LotteryTypeDaLeTou;
        
        [doubleColor release];
    }else if(indexPath.row==3){
    
        ThreeDBettingViewController *three3DViewController=[[ThreeDBettingViewController alloc]initWithNibName:@"ThreeDBettingViewController" bundle:nil];
        three3DViewController.title=@"3D";
        [self.navigationController pushViewController:three3DViewController animated:YES];
        [three3DViewController release];
    }else if(indexPath.row==4){
        ThreeDBettingViewController *three3DViewController=[[ThreeDBettingViewController alloc]initWithNibName:@"ThreeDBettingViewController" bundle:nil];
        three3DViewController.title=@"排列三";
        [self.navigationController pushViewController:three3DViewController animated:YES];
        [three3DViewController release];
    }else if(indexPath.row==5){
    
        ArraneFiveViewController *arraneViewController=[[ArraneFiveViewController alloc]initWithNibName:@"ArraneFiveViewController" bundle:nil];
        arraneViewController.title=@"排列五";
        [self.navigationController pushViewController:arraneViewController animated:YES];
        [arraneViewController release];
    }else if(indexPath.row==6){
    
        QiLeCaiViewController *qilecaiViewController=[[QiLeCaiViewController alloc]initWithNibName:@"QiLeCaiViewController" bundle:nil];
        qilecaiViewController.title=@"七乐彩";
        [self.navigationController pushViewController:qilecaiViewController animated:YES];
        qilecaiViewController.bettingView.minSelectNumber=7;
        qilecaiViewController.bettingView.maxSelectNumber=16;
        qilecaiViewController.bettingView.numOfBell=30;
        qilecaiViewController.bettingView.firstNumberIsZero=NO;
        [qilecaiViewController release];
    }else if(indexPath.row==7){
    }else if(indexPath.row==8){
        
        QiLeCaiViewController *qilecaiViewController=[[QiLeCaiViewController alloc]initWithNibName:@"QiLeCaiViewController" bundle:nil];
        qilecaiViewController.title=@"22选5";
        [self.navigationController pushViewController:qilecaiViewController animated:YES];
        qilecaiViewController.bettingView.minSelectNumber=5;
        qilecaiViewController.bettingView.maxSelectNumber=14;
        qilecaiViewController.bettingView.numOfBell=22;
        qilecaiViewController.bettingView.firstNumberIsZero=NO;
        [qilecaiViewController release];
        
    }
}


#pragma mark -刷新按钮

- (void)refreshView{

    
}
@end
